package org.idea.qiyu.framework.retry.guava;

import com.github.rholder.retry.Attempt;
import com.github.rholder.retry.RetryListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @Author linhao
 * @Date created in 9:35 上午 2021/10/4
 */
public class MyRetryListener implements RetryListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(MyRetryListener.class);


    @Override
    public <V> void onRetry(Attempt<V> attempt) {
        // 第几次重试(注意:第一次重试其实是第一次调用)
        System.out.printf("retry time : %s \n", attempt.getAttemptNumber());

        // 距离第一次重试的延迟
        System.out.printf("retry delay : %s  \n", attempt.getDelaySinceFirstAttempt());

        // 是否因异常终止
        if (attempt.hasException()) {
            System.out.printf("causeBy: %s  \n", attempt.getExceptionCause());
        }
        // 正常返回时的结果
        if (attempt.hasResult()) {
            System.out.printf("result=%s  \n", attempt.getResult());
        }
    }
}
